/**
 * Created by zhangguowei on 2015/12/10.
 */
$(function () {
    var time = $(".time span"), date = new Date(), year = date.getFullYear(), month = date.getMonth() + 1, day = date.getDay(), hour = date.getHours(), minutes = date.getMinutes(), second = date.getSeconds(), navBtn = $(".navBtn"), nav = $(".nav"), userName = $(".userName"), subNav = $(".subNav li a"), content = $(".content"), inputT = $("input[type=text]");
    var flip = 0;
    $(".navBtn").click(function (e) {
        if (flip++ % 2 === 0) {
            userName.css("text-indent", -200);
            //subNav.css("text-indent", -200);
            subNav.css("display",'none');
            nav.animate({"width": 60}, 300);
            content.animate({"padding-left": 80}, 300);
        } else {

            nav.animate({"width": 215}, 300, function () {
                userName.css("text-indent", 0);
                //subNav.css("text-indent", 55);
                subNav.css("display",'inline');
            });
            content.animate({"padding-left": 215}, 300);
        }
         e.preventDefault();
    });

    //navBtn.toggle(2000, function () {
    //    userName.css("text-indent", -200);
    //    subNav.css("text-indent", -200);
    //    nav.animate({"width": 60}, 300);
    //    content.animate({"padding-left": 80}, 300);
    //}, function () {
    //    nav.animate({"width": 215}, 300, function () {
    //        userName.css("text-indent", 0);
    //        subNav.css("text-indent", 55);
    //    });
    //    content.animate({"padding-left": 215}, 300);
    //});
    //setInterval(function () {
    //    date = new Date();
    //    hour = date.getHours();
    //    minutes = date.getMinutes();
    //    second = date.getSeconds();
    //    time.html(year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + second);
    //}, 1000);
    inputT.focus(function () {
        $(this).addClass("focus");
    });
    inputT.blur(function () {
        $(this).removeClass("focus");
    });
});
function createMenuTree(rtdata) {
    var data = eval("(" + rtdata + ")");
    if (data.IsOk) {
        var treeData = data.ReturnData;
        window["navtree"].ClearNodes();

        window["navtree"].InitTree(treeData.menu, data.treedefine);
        //$("#sysName").html(treeData.menu[0].description);
    } else {
        showWarningMsg("菜单没有数据!");
    }
}
function initMenu() {
    var tree = AddTreeView(document.getElementById("menuDiv"), "navtree");
    tree.NodeClick = null;
    tree.NodeCommand = null;　
    postData($basePath + "/queryAllMenus/"+$("#flag").val(), null, true, createMenuTree, null);
}

function getUserInfo() {
    $("img[alt='User Image']").attr("src", $basePath + "/master/dist/img/c55bfcb852df1187e12906382b2ea319.png");
    $.post($basePath + "/user/getSessionUser", function (data) {
        if (data && data.name != null && data.name != "") {
            $("p[class='userName']").html(data.name);
            $("#userLogName").html(data.logName);
        } else {
            layer.alert("会话已经失效，请重新登录", function () {
                top.location.href = 'index.jsp';
            })
        }
    });
}
initMenu();
getUserInfo();
$(function () {
    $('.subNav>li a').bind('click', function () {
        $('.subNav>li').css("background-color","#eee");
        $(this).parent().css("background-color","lightgrey")
    });

});

